<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>监听器的使用</title>
    <script src="https://cdn.jsdelivr.net/npm/vue@2.6.14/dist/vue.js"></script>
</head>
<body>
    <div id="app">
        米：<input type="text" v-model="m">
        <p></p>
        千米<input type="text" v-model="km">
    </div>
    <script>
        new Vue({
            el:'#app',
            data() {
                return {
                    m:0,
                    km:0
                }
            },
            watch:{
                m: function(val){
                    this.km = val / 1000
                },
                km: function(val){
                    this.m = val * 1000
                }
            }
        })
    </script>
</body>
</html>